﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using blackhouse.Data;

namespace blackhouse.WebNemo.Data {
    public sealed class ProcedureQuery {

        private List<ProcedureQueryParameter> parameters = new List<ProcedureQueryParameter>();

        internal string Procedure { get; private set; }
        internal ProcedureQueryParameter[] Parameters { get { return this.parameters.ToArray(); } }

        public ProcedureQuery(string procedure) {
            this.Procedure = procedure;
        }

        public void AddParameter(string name, object value) {
            this.AddParameter(name, value, DbType.String);
        }

        public void AddParameter(string name, object value, DbType type) {
            ProcedureQueryParameter parameter = new ProcedureQueryParameter();
            parameter.Name = name;
            parameter.Value = value;
            parameter.Type = type;
            this.parameters.Add(parameter);
        }

        public void AttachToDataHelper(AdoDataHelper dataHelper) {
            dataHelper.Reset();
            dataHelper.ProcedureName = this.Procedure;
            foreach (ProcedureQueryParameter parameter in this.parameters) {
                dataHelper.AddParameter(parameter.Name, parameter.Value, parameter.Type);
            }
        }

        public struct ProcedureQueryParameter {
            public string Name;
            public DbType Type;
            public object Value;
        }

    }
}
